package com.ecmcloud.flow.node.impl;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import com.ecmcloud.common.constants.ProcessInstanceConstant;
import com.ecmcloud.common.dto.Result;
import com.ecmcloud.common.dto.flow.Node;
import com.ecmcloud.common.dto.flow.NodeUser;
import com.ecmcloud.flow.node.AssignUserStrategy;
import com.ecmcloud.flow.utils.BizHttpUtil;
import com.google.common.collect.Lists;

/**
 * 来自角色
 */
@Component
public class AssignUserRoleStrategyImpl implements InitializingBean, AssignUserStrategy {
	
    @Override
    public List<String> handle(Node node, NodeUser rootUser, Map<String, Object> variables) {
        List<String> assignList = Lists.newArrayList();
        //角色
        List<NodeUser> nodeUserList = node.getNodeUserList();
        List<String> roleIdList = nodeUserList.stream().map(w -> w.getId()).collect(Collectors.toList());
        Result<List<String>> r = BizHttpUtil.queryUserIdListByRoleIdList(roleIdList);
        List<String> data = r.getData();
        assignList.addAll(data);
        return assignList;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        afterPropertiesSet(ProcessInstanceConstant.AssignedTypeClass.ROLE);
    }
}
